﻿// Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
// 作者:吕艳阳

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using XCI.Helper;

namespace XCI.Windows
{
    public class WidgetCaptionPopupGridControlEdit : FormCaptionPopupGridControlEdit
    {
        public override Type ModelType => typeof(WidgetCaptionAttribute);

        /// <summary>
        /// 异步绑定数据
        /// </summary>
        /// <returns>等待的任务</returns>
        public override async Task BindingDataAsync()
        {
            var list = await Task.Factory.StartNew(GetProviders);
            if (this.IsDisposing || this.IsDisposed) return;
            base.DataSource = list;
        }

        private List<WidgetCaptionAttribute> GetProviders()
        {
            return WinFormHelper.GetComponentCaptionProvider<WidgetCaptionAttribute>(p => ObjectHelper.ValidInterfaceClass(p, false, typeof(IWidget)));
        }
    }
}